package com.samse.plzcallme;

import android.content.Context;
import android.database.CharArrayBuffer;
import android.database.Cursor;
import android.provider.ContactsContract.Contacts;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.QuickContactBadge;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;

public class ContactListItemAdapter extends ResourceCursorAdapter {

	public ContactListItemAdapter(Context context, int layout, Cursor c) {
		super(context, layout, c);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
        final ContactListItemCache cache = (ContactListItemCache) view.getTag();
        TextView nameView = cache.nameView;
        //QuickContactBadge photoView = cache.photoView;
        // Set the name
        cursor.copyStringToBuffer(ContactPicker.SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
        int size = cache.nameBuffer.sizeCopied;
        cache.nameView.setText(cache.nameBuffer.data, 0, size);
        final long contactId = cursor.getLong(ContactPicker.SUMMARY_ID_COLUMN_INDEX);
        final String lookupKey = cursor.getString(ContactPicker.SUMMARY_LOOKUP_KEY);
        
//        cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));
	}

	public View newView(Context context, Cursor cursor, ViewGroup parent) {

	    View view = super.newView(context, cursor, parent);
	    ContactListItemCache cache = new ContactListItemCache();
	    cache.nameView = (TextView) view.findViewById(R.id.name);
	//    cache.phoneView = (TextView) view.findViewById(R.id.phone);
	    cache.emailView = (TextView) view.findViewById(R.id.email);
	    cache.imgView = (ImageView)view.findViewById(R.id.iv);
	    view.setTag(cache);
	    return view;

	}
	
	final static class ContactListItemCache {
//	    public QuickContactBadge photoView;
	    public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);
	    public TextView nameView, emailView;
	    public ImageView imgView;
	}


}
